package com.miao.aop01;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class Aop {

    //定义切点
    @Pointcut("execution( * com.miao.aop01.UserServiceImpl.*(..))")
    public void pointCut(){
    }

    @Before("pointCut()")
    public void before(JoinPoint joinPoint) {
        System.out.println(" @Before 开始调用接口");
    }

    @After("pointCut()")
    public void after(JoinPoint joinPoint) {
        System.out.println(" @After 结束调用接口");
    }


    @Around("pointCut()")
    public void around(ProceedingJoinPoint jp) {

        try{
            System.out.println(" 环绕通知前");
            jp.proceed();
            System.out.println(" 环绕通知后");
        } catch(Throwable e){
            System.out.println("异常发生");
        }
    }

}
